package com.zhf.entity.es;

import com.zhf.entity.Product;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

@Data
@Document(indexName = "lagou",type = "product")
public class EsProduct {

    @Id
    private Long id;
    @Field(type = FieldType.Text,analyzer = "ik_max_word", store = true)
    private String name;
    @Field(type = FieldType.Double)
    private Double price;
    @Field(type = FieldType.Keyword, store = true)
    private String flag;
    @Field(type = FieldType.Text, analyzer = "ik_max_word", store = true)
    private String goods_desc;
    @Field(type = FieldType.Keyword, index = false, store = true)
    private String images;
    @Field(type = FieldType.Integer)
    private Integer goods_stock;
    @Field(type = FieldType.Keyword, store = true)
    private String goods_type;

    public EsProduct(Product product){
        this.id = product.getId();
        this.name = product.getName();
        this.price = product.getPrice();
        this.flag = product.getFlag();
        this.goods_desc = product.getGoodsDesc();
        this.images = product.getImages();
        this.goods_stock = product.getGoodsStock();
        this.goods_type = product.getGoodsType();
    }
}
